package com.bort.system.schedule;

import com.bort.system.common.DataContainer;
import com.bort.system.controller.client.DeskController;
import com.bort.system.service.TDeskService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.Map;

@Component
public class AutoCheckOutScheduler {

    @Resource
    TDeskService deskService;

    @Scheduled(fixedRate = 10000)
    void autoCheckOut(){
        deskService.refreshData();
    }

    @Scheduled(initialDelay = 10000,fixedRate = 3000)
    void autoRefreshDesk(){
        Map<Integer, DeskController> ctrlMap = DataContainer.deskCtrlMap;
        if(ctrlMap != null){
            Iterator<Integer> keyIter = ctrlMap.keySet().iterator();
            while (keyIter.hasNext()){
                Integer dataId = keyIter.next();
                DeskController ctrl = ctrlMap.get(dataId);
                ctrl.refreshDeskData();
            }
        }
    }
}
